package com.egao.orderB.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.orderB.entity.BillFeeWriteOffItem;
import com.egao.orderB.service.BillFeeWriteOffItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.ui.Model;


/**
 *
 * 销账列表的销账记录
 * @author : Doman
 * @date : 2021-04-19 17:05:50
 * @version ：1.0
 */

@Api(tags = "销账列表的销账记录")
@RestController
@RequestMapping("/api/orderB/billFeeWriteOffItem")
public class BillFeeWriteOffItemController extends BaseController {

	@Autowired
	private BillFeeWriteOffItemService billFeeWriteOffItemService;

	/**
	 * 分页查询列表
	 */
	@PreAuthorize("hasAuthority('orderB:billFeeWriteOff:list')")
    //@OperLog(value = "销账列表的销账记录", desc = "分页查询")
    @ApiOperation(value ="分页查询销账列表的销账记录",notes = "" +
        "limit:每页显示几行 必填\n" +
        "page:第几页 必填\n" +
        "writeOffId:销账列表id\n" +
        " \n\n\n" +
        "返回的结果:\n" +
        "id:id\n" +
        "writeOffId:销账列表id\n" +
        "invoicename:抬头\n" +
        "billOfLading:提单号\n" +
        "boxNum:箱号\n" +
        "packDate:装箱时间\n" +
        "price:金额\n" +
        "profitLoss:损益\n" +
        "type:类型 应收应付\n" +
        "remark:备注\n" +
        "createTime:创建时间\n" +
        "createUser:创建人\n" +
        "updateTime:更新时间\n" +
        "updateUser:更新人\n" +
        "",httpMethod = "POST")
    @ApiPageParam
    @PostMapping("/list")
    public JsonResult page(PageResult2<T> page, BillFeeWriteOffItem billFeeWriteOffItem) throws Exception{
        return billFeeWriteOffItemService.list(page, billFeeWriteOffItem, getLoginUser());
    }

    /**
     * 查询全部销账列表的销账记录
     */
    @PreAuthorize("hasAuthority('orderB:billFeeWriteOff:list')")
    //@OperLog(value = "销账列表的销账记录", desc = "查询全部")
    @ApiOperation("查询全部销账列表的销账记录")
    @PostMapping("/listAll")
    public JsonResult list(BillFeeWriteOffItem billFeeWriteOffItem){
        return billFeeWriteOffItemService.list(billFeeWriteOffItem, getLoginUser());
    }

    /**
     * 根据id查询销账列表的销账记录
     */
    @PreAuthorize("hasAuthority('orderB:billFeeWriteOff:list')")
    //@OperLog(value = "销账列表的销账记录", desc = "根据id查询")
    @ApiOperation("根据id查询销账列表的销账记录")
    @PostMapping("/get")
    public JsonResult get(BillFeeWriteOffItem billFeeWriteOffItem) {
        return billFeeWriteOffItemService.getById(billFeeWriteOffItem);
		// 使用关联查询
        //PageParam<billFeeWriteOffItem> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<billFeeWriteOffItem> records = billFeeWriteOffItemService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加销账列表的销账记录
     */
    @PreAuthorize("hasAuthority('orderB:billFeeWriteOff:save')")
    @OperLog(value = "销账列表的销账记录", desc = "添加", param = false, result = true)
    @ApiOperation(value ="添加销账列表的销账记录",notes = "" +
           "invoicename:抬头\n" +
           "billOfLading:提单号\n" +
           "boxNum:箱号\n" +
           "packDate:装箱时间\n" +
           "price:金额\n" +
           "profitLoss:损益\n" +
           "type:类型 应收应付\n" +
           "remark:备注\n" +
        "",httpMethod = "POST")
    @PostMapping("/save")
    public JsonResult save(Model model, BillFeeWriteOffItem billFeeWriteOffItem) {
        return billFeeWriteOffItemService.save(billFeeWriteOffItem, getLoginUser());
    }

    /**
     * 修改销账列表的销账记录
     */
    @PreAuthorize("hasAuthority('orderB:billFeeWriteOff:update')")
    @OperLog(value = "销账列表的销账记录", desc = "修改", param = false, result = true)
    @ApiOperation(value ="修改销账列表的销账记录",notes = "" +
           "id:id\n" +
           "invoicename:抬头\n" +
           "billOfLading:提单号\n" +
           "boxNum:箱号\n" +
           "packDate:装箱时间\n" +
           "price:金额\n" +
           "profitLoss:损益\n" +
           "type:类型 应收应付\n" +
           "remark:备注\n" +
        "",httpMethod = "POST")
    @PostMapping("/update")
    public JsonResult update(Model model, BillFeeWriteOffItem billFeeWriteOffItem) {
        return billFeeWriteOffItemService.update(billFeeWriteOffItem, getLoginUser());
    }

    /**
     * 删除销账列表的销账记录
     */
    @PreAuthorize("hasAuthority('orderB:billFeeWriteOff:remove')")
    @OperLog(value = "销账列表的销账记录", desc = "删除", result = true)
    @ApiOperation("删除销账列表的销账记录")
    @PostMapping("/remove")
    public JsonResult remove(BillFeeWriteOffItem billFeeWriteOffItem ) {
        return billFeeWriteOffItemService.remove(billFeeWriteOffItem, getLoginUser());
    }

    /**
     * 批量添加销账列表的销账记录
     */
    /**@RequiresPermissions("orderB:billFeeWriteOff:save")
    @OperLog(value = "销账列表的销账记录", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<BillFeeWriteOffItem> list) {
        if (billFeeWriteOffItemService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改销账列表的销账记录
     */
    /**@RequiresPermissions("orderB:billFeeWriteOff:update")
    @OperLog(value = "销账列表的销账记录", desc = "批量修改", result = true)
    @ResponseBody
    @PostMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<BillFeeWriteOffItem> batchParam) {
        if (batchParam.update(billFeeWriteOffItemService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除销账列表的销账记录
     */
    /**@RequiresPermissions("orderB:billFeeWriteOff:`remove")
    @OperLog(value = "销账列表的销账记录", desc = "批量删除", result = true)
    @ResponseBody
    @PostMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (billFeeWriteOffItemService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
